"use strict";

var passwordKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYqxNMjTRQIvf9JylgBaCOwdAvE3XwWJownq8K8iy5FDMaC7wYHmbw6s+B66TcOYLZFy10mUYxkV+J+epmpnIxMSdXYZ7sU2pqbB9tZmtdkiy4YLoXQUirwaZsEJSApQF/P9StfqAralyG2wguBYyujF8EdV4Kbrb5vD+QTxcwxQIDAQAB";

$(function () {
    toastr.options = {
        closeButton: false,
        debug: false,
        progressBar: true,
        positionClass: "toast-top-center",
        onclick: null,
        showDuration: "300",
        hideDuration: "1000",
        timeOut: "2000",
        extendedTimeOut: "1000",
        showEasing: "swing",
        hideEasing: "linear",
        showMethod: "fadeIn",
        hideMethod: "fadeOut"
    };
    $("#forgetBtn").click(function () {
        location.href = "fogetPassword.html";
    });

    //登录提交
    $("#submit").click(function () {
        var params = {
            phone: $(".userPhone").val(),
            password: $(".password").val()
        };
        if (!params.phone) {
            return toastr.info('请输入用户手机号');
        }
        if (!params.password) {
            return toastr.info('请输入密码');
        }
        console.log(params);
        //此处调用登录接口  并把用户信息存在全局 window/localStorge中 跳转至首页
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(passwordKey);
        var password_Encry = encrypt.encrypt($(".password").val());

        params.password = password_Encry;
        $.server(params, '/iagent/v1/login').then(function (res) {
            localStorage.hz_userInfo = JSON.stringify(res.result);
            sessionStorage.hz_userInfo = JSON.stringify(res.result);

            location.href = "index.html";
        });
    });
});